package com.learn.publish;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Subscriber subscriber1 = new Subscriber("张三", new Subscriber.Receiver() {
            @Override
            public void onMessage(String publisher, String msg) {
                // 收到消息
                System.out.println(publisher + ":" + msg);
            }
        }); // 创建订阅者张三
        Subscriber subscriber2 = new Subscriber("李四"); // 创建订阅者李四
        Subscriber subscriber3 = new Subscriber("王五"); // 创建订阅者王五

        EventBus eventBus = new EventBus("小明");
        eventBus.emit(subscriber1); // 添加张三订阅者
        eventBus.emit(subscriber2); // 添加李四订阅者
        eventBus.emit(subscriber3); // 添加王五订阅者

        eventBus.on("祝你虎年大吉大利"); // 发布新消息

    }

}
